package com.highspeed.bdk.bean.entity.logic;

import com.bianmaba.spring.data.jpa.domain.annotations.QueryCacheable;
import com.highspeed.bdk.bean.base.BaseEntity;
import com.highspeed.bdk.bean.base.IncrementEntity;
import com.highspeed.bdk.bean.entity.ViewPostion;
import com.highspeed.bdk.bean.entity.physical.PhysicalLink;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenjiabin on 2018/3/24.
 */
@Entity
@DynamicUpdate(true)
@DynamicInsert(true)
@QueryCacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class App extends IncrementEntity {
    @Column(nullable = false, length = 128)
    private String name;

    @Column(length = 32)
    private String version;

    @Column(length = 255)
    private String icon;

    @Column(length = 255)
    private String remark;

    @ManyToOne()
    @JoinColumn(name = "logicTopology_id")
    private LogicTopology logicTopology;

    @ManyToOne()
    @JoinColumn(name = "PreinstalledRefLogicTopology_id")
    private LogicTopology preinstalledRedLogicTopology;

    public LogicTopology getPreinstalledRedLogicTopology() {
        return preinstalledRedLogicTopology;
    }

    public void setPreinstalledRedLogicTopology(LogicTopology preinstalledRedLogicTopology) {
        this.preinstalledRedLogicTopology = preinstalledRedLogicTopology;
    }

    /**
     * 此映射无GET及SET函数，只用于维护关系用（在对应APP被移除时可以自动移除链路）
     */
    @OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, mappedBy = "leftApp")
    private List<LogicLink> rightLinks = new ArrayList<LogicLink>(0);
    /**
     * 此映射无GET及SET函数，只用于维护关系用（在对应APP被移除时可以自动移除链路）
     */
    @OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, mappedBy = "rightApp")
    private List<LogicLink> leftLinks = new ArrayList<LogicLink>(0);

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public LogicTopology getLogicTopology() {
        return logicTopology;
    }

    public void setLogicTopology(LogicTopology logicTopology) {
        this.logicTopology = logicTopology;
    }
}
